﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Example.Persistence
{
    public class EntitySet<TEntity> : IEntitySet<TEntity> where TEntity : class
    {
        private readonly DbSet<TEntity> dbSet;

        public EntitySet(DbSet<TEntity> dbSet)
        {
            Contract.Requires(dbSet != null);

            this.dbSet = dbSet;
        }

        public TEntity Add(TEntity entity)
        {
            return this.dbSet.Add(entity);
        }

        public TEntity Remove(TEntity entity)
        {
            return this.dbSet.Remove(entity);
        }

        public IEnumerator<TEntity> GetEnumerator()
        {
            return ((IEnumerable<TEntity>)this.dbSet).GetEnumerator();
        }

        public Type ElementType
        {
            get { return ((IQueryable)this.dbSet).ElementType; }
        }

        public Expression Expression
        {
            get { return ((IQueryable<TEntity>)this.dbSet).Expression; }
        }

        public IQueryProvider Provider
        {
            get { return ((IQueryable<TEntity>)this.dbSet).Provider; }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable)this.dbSet).GetEnumerator();
        }

        public IQueryable<TEntity> Include(string path)
        {
            return this.dbSet.Include(path);
        }
    }
}
